package ua.kpi_java_training.zastupaylo.module1;

import org.junit.After;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.ArrayList;

/**
 * Tests for PalindromeFinder.class
 *
 * @version 1.4
 * @author Zastupaylo Alexander (zastupaylo@gmailcom)
 */
public class PalindromeFinderTest {

    @After
    public void tearDown() {
        PalindromeFinder.palindromes.clear();
    }

    /**
     * Test findPalindrome() method with string containing palindromes.
     */
    @Test
    public void testFindPalindromeWith() {
        String error = "Test FindPalindromeWith FAILED";
        String inputPhrase = "ovovokak";
        ArrayList<String> expectedPalindromes = new ArrayList<String>() {{
            add("ovo");
            add("vov");
            add("ovo");
            add("kak");
            add("ovovo");
        }};
        PalindromeFinder.findPalindrome(inputPhrase);
        assertEquals(error, PalindromeFinder.palindromes, expectedPalindromes);
    }

    /**
     * Test findPalindrome() method with string not containing palindromes.
     */
    @Test
    public void testFindPalindromeWithout() {
        String error = "Test FindPalindromeWithout FAILED";
        String inputPhrase = "intellij idea";
        ArrayList<String> expectedPalindromes = new ArrayList<String>();
        PalindromeFinder.findPalindrome(inputPhrase);
        assertEquals(error, PalindromeFinder.palindromes, expectedPalindromes);
    }

    /**
     * Test findAllSpecifiedLengthPalindromes() method with string containing palindromes
     * of specified length.
     */
    @Test
    public void testFindSpecifiedLengthPalindromesWith() {
        String error = "Test FindSpecifiedLengthPalindromesWith FAILED";
        String inputPhrase = "ovovokak";
        int specifiedLength = 3;
        ArrayList<String> expectedPalindroms = new ArrayList<String>() {{
            add("ovo");
            add("vov");
            add("ovo");
            add("kak");
        }};
        PalindromeFinder.findSpecifiedLengthPalindromes(specifiedLength, inputPhrase);
        assertEquals(error, PalindromeFinder.palindromes, expectedPalindroms);
    }

    /**
     * Test findAllSpecifiedLengthPalindromes() method with string NOT containing palindromes
     * of specified length.
     */
    @Test
    public void testFindSpecifiedLengthPalindromesWithout() {
        String error = "Test FindSpecifiedLengthPalindromesWithout FAILED";
        String inputPhrase = "ovovokak";
        int specifiedLength = 4;
        ArrayList<String> expectedPalindromes = new ArrayList<String>();
        PalindromeFinder.findSpecifiedLengthPalindromes(specifiedLength, inputPhrase);
        assertEquals(error, PalindromeFinder.palindromes, expectedPalindromes);
    }


    @Test
    public void testIsPalindromeTrue() throws Exception {
        String error = "Test IsPalindromeTrue FAILED";
        String palindrome = "ovovo";
        assertEquals(error, PalindromeFinder.isPalindrome(palindrome), true);
    }

    @Test
    public void testIsPalindromeFalse() throws Exception {
        String error = "Test IsPalindromeFalse FAILED";
        String notPalindrome = "idea";
        assertEquals(error, PalindromeFinder.isPalindrome(notPalindrome), false);
    }
}
